<template>
	<view class="start-index" v-if="systemShow === 0">
		<view v-if="tabberPageLoadFlag[0]" :style="{display: currentIndex === 0 ? '' : 'none'}">
			<scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
				<home :isFlush="isFlush" ref="home"></home>
			</scroll-view>
		</view>
		<view v-if="tabberPageLoadFlag[1]" :style="{display: currentIndex === 1 ? '' : 'none'}">
			<scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
				<circle-page ref="circleRef"></circle-page>
			</scroll-view>
		</view>
		<view v-if="tabberPageLoadFlag[2]" :style="{display: currentIndex === 2 ? '' : 'none'}">
			<scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
				<People ref="people"></People>
			</scroll-view>
		</view>
		<view v-if="tabberPageLoadFlag[3]" :style="{display: currentIndex === 3 ? '' : 'none'}">
			<scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
				<Message :ref="message"></Message>
			</scroll-view>
		</view>
		<view v-if="tabberPageLoadFlag[4]" :style="{display: currentIndex === 4 ? '' : 'none'}">
			<scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
				<mine :userInfo="userInfo" ref="mine"></mine>
			</scroll-view>
		</view>

		<tn-tabbar v-model="currentIndex" :list="tabbarList" activeColor="#838383" inactiveColor="#AAAAAA"
			activeIconColor="#FBBD12" :animation="true" :safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar>
	</view>
	<view v-else class="centered-text">
		<scroll-view class="template-index tn-safe-area-inset-bottom" style="height: 1900rpx;" scroll-y="true">
		  
		  <!-- 安卓酷炫顶部自定义导航，为什么要分成安卓和苹果的导航？你试试就知道为什么了，很多骚操作在苹果不生效 -->
		  <view v-if="isAndroid" class="" style="width: 100%;height: 220rpx;background: linear-gradient(0deg, rgba(255,255,255,0), rgba(0,0,0,0.16));position: fixed;top: 0;z-index: 1;">
		    <tn-nav-bar fixed :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF00">
		      <view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
		        <!-- 图标logo -->
		        <view class="custom-nav__back" @click="tn('/homePages/about')">
		          <!-- 图片模式-->
		          <view class="logo-pic tn-shadow-blur" style="background-image:url('')">
		            <view class="logo-image">
		            </view>
		          </view> 
		          <!-- 如果有图片那就放图片，如果没有，那就删掉上面的放字体icon -->
		          <!-- <view class="tn-icon-left"></view> -->
		        </view>
		        <!-- 搜索框 -->
		      </view>
		    </tn-nav-bar>
		  </view>
		  
		  
		  <!-- 轮播banner-->
		  <swiper class="card-swiper" @click="tn('')" :circular="true" 
		    :autoplay="true" duration="500" interval="8000" @change="cardSwiper"> 
		    <swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
		      <view class="swiper-item image-banner">
		        <image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
		      </view>
		      <view class="swiper-item-text">
		        <view class="tn-text-bold tn-color-white" style="font-size: 90rpx;">{{item.title}}</view>
		        <view class="tn-color-white tn-padding-top" style="font-size: 30rpx;">{{item.name}}</view>
		        <view class="tn-text-sm tn-text-bold tn-color-white tn-padding-top-sm tn-padding-bottom-sm">{{item.text}}</view>
		      </view>
		    </swiper-item>
		  </swiper>
		  <view class="indication">
		      <block v-for="(item,index) in swiperList" :key="index">
		          <view class="spot" :class="cardCur==index?'active':''"></view>
		      </block>
		  </view>
		    
		  
		  <!-- 通知-->
		  <view class="tn-bg-white tn-margin-top" style="border-radius: 20rpx;">
		    <tn-notice-bar :list="list" mode="vertical" leftIconName="notice"></tn-notice-bar>
		  </view>
		  
		  <view class='tn-tabbar-height'></view>
		  
		</scroll-view>
	</view>
</template>

<script>
	import Home from './home/home.vue'
	import CirclePage from './circle/circle.vue'
	import People from './peopel/peopel.vue'
	import Mine from './mine/mine.vue'
	import Message from './message/message.vue'
	import request from "@/common/request.js"
	import config from "@/common/config.js"
	import {
		data
	} from '../libs/mixin/template_page_mixin'
	export default {
		components: {
			Home,
			CirclePage,
			People,
			Message,
			Mine,
			//DataList
		},
		name: 'Home',
		data() {
			return {
				// 底部tabbar菜单数据
				tabbarList: [{
						title: '首页',
						activeIcon: '/static/tabbar/home_tnnew.png',
						inactiveIcon: '/static/tabbar/home_tn.png'
					},
					{
						title: '圈子',
						activeIcon: '/static/tabbar/circle_tnnew.png',
						inactiveIcon: '/static/tabbar/circle_tn.png'
					},
					{
						title: '广场',
						activeIcon: 'menu-circle',
						inactiveIcon: 'rocket',
						activeIconColor: '#FFFFFF',
						inactiveIconColor: '#FFFFFF',
						iconSize: 50,
						out: true
					},
					{
						title: '消息',
						activeIcon: '/static/tabbar/preferred_tnnew.png',
						inactiveIcon: '/static/tabbar/preferred_tn.png',
					},
					{
						title: '我的',
						activeIcon: '/static/tabbar/mine_tnnew.png',
						inactiveIcon: '/static/tabbar/mine_tn.png'
					}
				],
				// tabbar当前被选中的序号
				currentIndex: 0,
				// 自定义底栏对应页面的加载情况
				tabberPageLoadFlag: [],
				userInfo: {},
				dataList: [],
				systemShow: 0,
				///////
				cardCur: 0,
				isAndroid: true,
				swiperList: [],
				
				list: [
				  '西江君心官网，欢迎大家进入！',
				  '感谢各位用户的大力支持！'
				],
				
				searlist: [],
				
				tuniaoData: [],
				isFlush: true,
			}
		},
		created() {
		  const systemInfo = uni.getSystemInfoSync()
		  if (systemInfo.system.toLocaleLowerCase().includes('ios')) {
		    this.isAndroid = false
		  } else {
		    this.isAndroid = true
		  }
		},
		onLoad(options) {
			this.getWxSystemSync(options);
		},
		onShow() {
			if(this.currentIndex == 4){
				this.userInfo = uni.getStorageSync("userInfo");
			}
			
			if(this.currentIndex == 3){
				uni.$emit("loadMsg")
			}
			
			if(this.currentIndex == 1){
				uni.$emit("circle")
			}
		},
		watch: {
			currentIndex(newVal, old) {
				if (newVal == 4) {
					this.userInfo = uni.getStorageSync("userInfo");
				}

				if (newVal == 2) {
					uni.$emit("peopel")
				}

				if (newVal == 3) {
					uni.$emit("loadMsg")
				}
				
				/* 
				if (newVal == 1) {
					uni.$emit("circle")
				}*/
				
				if (newVal == 0) {
					this.isFlush = !this.isFlush
				}
			}
		},
		methods: {
			 getWxSystemSync(options){
				// await this.getWxSystem2()
				
				//if(this.systemShow < 1){
					const index = Number(options.index || 0)
					// 根据底部tabbar菜单列表设置对应页面的加载情况
					this.tabberPageLoadFlag = this.tabbarList.map((item, tabbar_index) => {
						return index === tabbar_index
					})
					this.switchTabbar(index)
				//}
			},
			// cardSwiper
			cardSwiper(e) {
			  this.cardCur = e.detail.current
			},
			// getWxSystem2(){
			// 	let _t = this
			// 	return new Promise((resolve, reject)=>{
			// 		uni.request({
			// 			url:config.webUrl + "friend/wx/system/getFlag",
			// 			method:"GET",
			// 			success(res) {
			// 				let _data = res.data
			// 				if (_data.code == 20000) {
			// 					_t.systemShow=_data.data
			// 				}
			// 				resolve('suc')
			// 			},
			// 			fail(err) {
			// 				reject('err');
			// 			}
			// 		})
			// 	})
			// },
			turnLogin() {
				uni.removeStorageSync("token")
				uni.removeStorageSync("userInfo")
				uni.navigateTo({
					url: '/minePages/login',
				});
			},
			switchTabbar(index) {
				this._switchTabbarPage(index);
				if (index !== 2 && index !== 0) {
					this.$refs?.circleRef?.stopAllVideo();
				}
			},
			// 导航页面滚动到底部
			tabbarPageScrollLower(e) {
				if (this.currentIndex === 3) {
					this.$refs.preferredRef.getRandomData && this.$refs.preferredRef.getRandomData()
				}
			},

			// 切换导航页面
			_switchTabbarPage(index) {
				const selectPageFlag = this.tabberPageLoadFlag[index]
				if (selectPageFlag === undefined) {
					return
				}
				if (selectPageFlag === false) {
					this.tabberPageLoadFlag[index] = true
				}
				this.currentIndex = index
			}
		}
	}
</script>

<style lang="scss" scoped>
 .template-index{
    max-height: 100vh;
  }
  .tn-tabbar-height {
  	min-height: 100rpx;
  	height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  }
  
  /* 阴影*/
  .home-shadow{
      box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  
  /* 自定义导航栏内容 start */
  .custom-nav {
    height: 100%;
    
    &__back {
      margin: auto 5rpx;
      font-size: 40rpx;
      margin-right: 10rpx;
      margin-left: 30rpx;
      flex-basis: 5%;
    }
    
    &__search {
      flex-basis: 60%;
      width: 100%;
      height: 100%;
      
      &__box {
        width: 100%;
        height: 70%;
        padding: 10rpx 0;
        margin: 0 30rpx;
        border-radius: 60rpx 60rpx 0 60rpx;
        font-size: 24rpx;
      }
      
      &__icon {
        padding-right: 10rpx;
        margin-left: 20rpx;
        font-size: 30rpx;
      }
      
      &__text {
        // color: #AAAAAA;
      }
    }
  }
  .logo-image{
    width: 65rpx;
    height: 65rpx;
    position: relative;
  }
  .logo-pic{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:top;
    border-radius: 50%;
  }
  /* 自定义导航栏内容 end */
  

  /* 轮播视觉差 start */
  .card-swiper {
    height: 500rpx !important;
  }
    
  .card-swiper swiper-item {
    width: 750rpx !important;
    left: 0rpx;
    box-sizing: border-box;
    // padding: 0rpx 30rpx 90rpx 30rpx;
    overflow: initial;
  }
    
  .card-swiper swiper-item .swiper-item {
    width: 100%;
    display: block;
    height: 100%;
    transform: scale(1);
    transition: all 0.2s ease-in 0s;
    will-change: transform;
    overflow: hidden;
  }
    
  .card-swiper swiper-item.cur .swiper-item {
    transform: none;
    transition: all 0.2s ease-in 0s;
    will-change: transform;
  }
    
  .card-swiper swiper-item .swiper-item-text {
    margin-top: -300rpx;
    text-align: center;
    width: 100%;
    display: block;
    height: 50%;
    border-radius: 10rpx;
    transform: translate(100rpx, 0rpx) scale(0.9, 0.9);
    transition: all 0.6s ease 0s;
    will-change: transform;
    overflow: hidden;
  }
    
  .card-swiper swiper-item.cur .swiper-item-text {
    margin-top: -300rpx;
    width: 100%;
    transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
    transition: all 0.6s ease 0s;
    will-change: transform;
  }
  
  .image-banner{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .image-banner image{
    width: 100%;
    height: 100%;
  }
  
  /* 轮播指示点 start*/
  .indication{
    z-index: 9999;
    width: 100%;
    height: 36rpx;
    position: absolute;
    display:flex;
    flex-direction:row;
    align-items:center;
    justify-content:center;
  }
  
  .spot{
    background-color: #FFFFFF;
    opacity: 0.4;
    width: 10rpx;
    height: 10rpx;
    border-radius: 20rpx;
    top: -60rpx;
    margin: 0 8rpx !important;
    position: relative;
  }
  
  .spot.active{
    opacity: 0.6;
    width: 30rpx;
    background-color: #FFFFFF;
  }
  
  /* 资讯主图 start*/
  .image-article {
    border-radius: 8rpx;
    width: 220rpx;
    height: 120rpx;
    position: relative;
  }
  
  .image-pic{
    // border: 1rpx solid #F8F7F8;
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:top;
    border-radius: 10rpx;
  }
  
  /* 文字截取*/
  .clamp-text-1 {
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
  .clamp-text-2 {
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
  .blue-title::before {
    content: "";
    position: absolute;
    display: block;
    width: 80rpx;
    height: 26rpx;
    background: #269EFC;
    margin-top: 24rpx;
    margin-left: 75rpx;
    opacity: 0.3;
    z-index: -1;
    border-radius: 4rpx;
  }
  
  
 .icon12 {
   &__item {
     transform: scale(1);
     transition: transform 0.3s linear;
     transform-origin: center center;
     
     &--icon {
       width: 100rpx;
       height: 100rpx;
       font-size: 60rpx;
       border-radius: 50%;
       margin-bottom: 18rpx;
       position: relative;
       z-index: 1;
       
       &::after {
         content: " ";
         position: absolute;
         z-index: -1;
         width: 100%;
         height: 100%;
         left: 0;
         bottom: 0;
         border-radius: inherit;
         opacity: 1;
         transform: scale(1, 1);
         background-size: 100% 100%;
         background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg2.png);
 
           
       }
     }
   }
 }


  /* 热门图片 start*/
  .image-tuniao1{
    padding: 164rpx 0rpx 162rpx 0rpx;
    font-size: 40rpx;
    font-weight: 300;
    position: relative;
  }
  .image-tuniao2{
    padding: 74rpx 0rpx;
    font-size: 40rpx;
    font-weight: 300;
    position: relative;
  }
  .image-tuniao3{
    padding: 90rpx 0rpx;
    font-size: 40rpx;
    font-weight: 300;
    position: relative;
  }
  .image-pic{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:top;
    border-radius: 10rpx;
  }
  /* 胶囊banner*/
  .image-capsule{
    padding: 100rpx 0rpx;
    font-size: 40rpx;
    font-weight: 300;
    position: relative;
  }
  .image-piccapsule{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:top;
    border-radius: 20rpx 20rpx 0 0;
  }
  
  /* 工作区展示 start */
  .tn-info {
    
    &__container {
      margin-top: 10rpx;
      margin-bottom: 50rpx;
    }
    
    &__item {
      width: 47.7%;
      margin: 15rpx 0rpx 30rpx 0rpx;
      padding: 40rpx 30rpx;
      border-radius: 10rpx;
      
  
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/2.png);
        }
      
      &__left {
        
        &--icon {
          width: 80rpx;
          height: 80rpx;
          border-radius: 50%;
          font-size: 40rpx;
          margin-right: 20rpx;
          position: relative;
          z-index: 1;
          
          &::after {
            content: " ";
            position: absolute;
            z-index: -1;
            width: 100%;
            height: 100%;
            left: 0;
            bottom: 0;
            border-radius: inherit;
            opacity: 1;
            transform: scale(1, 1);
            background-size: 100% 100%;
            background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg5.png);
          }
        }
        
        &__content {
          font-size: 25rpx;          
          
          &--data {
            color: rgba(255,255,255,0.5);
            margin-top: 5rpx;
            // font-weight: bold;
          }
        }
      }
      
      &__right {
        &--icon {
          position: absolute;
          right: 0rpx;
          top: 50rpx;
          font-size: 100rpx;
          width: 108rpx;
          height: 108rpx;
          text-align: center;
          line-height: 60rpx;
          opacity: 0.15;  
        }
      }
      &__bottom {
        box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.12);
        border-radius: 0 0 10rpx 10rpx;
        position: absolute;
        width: 85%;
        line-height: 15rpx;
        left: 50%;
        bottom: -15rpx;
        transform: translateX(-50%);
        z-index: -1;
        text-align: center;
      }
    }
  }
</style>
